package com.novacloud.fresh.service.impl.login;

import com.novacloud.fresh.dao.login.DUserMapper;
import com.novacloud.fresh.model.login.DUser;
import com.novacloud.fresh.model.login.DUserExample;
import com.novacloud.fresh.service.login.DUserService;
import com.novacloud.fresh.util.ConstantModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/4/14 0014.
 */
@Service("dUserService")
public class DUserServiceImpl implements DUserService {
    @Autowired
    private DUserMapper duserMapper;

    @Override
    public DUser getByUserName(String username) {
        DUserExample duserExample = new DUserExample();
        duserExample.createCriteria().andCodeEqualTo(username);
        duserExample.createCriteria().andIsusingEqualTo(ConstantModel.STATE_Y);
        List<DUser> users = duserMapper.selectByExample(duserExample);
        if (users.size() != 1) {
            throw new IncorrectResultSizeDataAccessException(users.size());
        } else {
            return users.get(0);
        }
    }

    @Override
    public DUser selectByPrimaryKey(String id) {
        return duserMapper.selectByPrimaryKey(id);
    }
}
